#include <iostream>  
#include <conio.h>  
#include <windows.h>  
#include <math.h> 
    
#define PARA 3.3; // for jumpTime
int repeatFlag=0;

bool getKey(char key)
{
	
	if(GetAsyncKeyState(key) & 0x8000) 
	{	
		if(key=='R')
		repeatFlag=1;
	
		return true;
	}
	else
		return false;
}
int main()
{  
    POINT mptrA,mptrB;  //remember the coordinate of mouse 
	int jumpTime,distance;
	std::cout<<"\t\t*******************Introduction*****************"<<std::endl;
	std::cout<<"\t\t*********************BY Nirvana*****************"<<std::endl;
	std::cout<<"\t\tpress A to set A point,press S to set B point"<<std::endl;
	std::cout<<"\t\tpress space to jump,R to reset A and B point"<<std::endl;
    while(1)
	{  
		again:
        while(getKey('A'))    //A
		{  
            GetCursorPos(&mptrA);
			Sleep(500);
			std::cout<<"\t\tget point A ("<<mptrA.x<<","<<mptrA.y<<")"<<std::endl;
			
		}
		
		while(getKey('S'))   //B
		{  
			GetCursorPos(&mptrB);
			Sleep(500);
			std::cout<<"\t\tget point B ("<<mptrB.x<<","<<mptrB.y<<")"<<std::endl;
			
			
		} 
		distance=sqrt(pow((mptrA.x-mptrB.x),2)+pow((mptrA.y-mptrB.y),2)); //distance of the screen
		jumpTime=distance*PARA;//need to modify	
		
		while(getKey(VK_SPACE)||getKey('R'))  
		{
			Sleep(500);
			if(repeatFlag)
			{
				std::cout<<"\t\tplease reset A point and B point"<<std::endl;
				repeatFlag=0;
				goto again;
			}
			else
			{
			std::cout<<"\t\tjump:"<<jumpTime<<std::endl;
			std::cout<<"\t\tjump>>>>>>>>>>>>>>>>>>>>>>>>>"<<std::endl;
			mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);  
			Sleep(jumpTime); 
			mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); 
			}
		} 			
			 
        
		
		
    }  
} 